<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>防刷配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script type="text/javascript" src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <style>
        body {
            background-color: #ffffff;
        }
        label.required:after {
        	  content:'*';
        	  color:red;
        }   
        .delbtn{
            position: relative;
            display: inline-block;
            background: #FFB800;
            border: 1px solid #FFB800;
            border-radius: 2px;
            padding: 4px 12px;
            overflow: hidden;
            color: #FFFFFF;
            text-decoration: none;
            text-indent: 0;
            line-height: 27px;
            width:92px;
        }             
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            限流配置文档说明”：1. <a href="#" target="_blank">限流说明</a> 2. <a href="#" target="_blank">规则说明？</a>
        </blockquote>
        <form class="layui-form layui-form-pane"  action="" lay-filter="UpdateInfo">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>全局配置项</legend>
            </fieldset>           
             
            <div class="layui-form-item">
            <input type="hidden" name="id" readonly="true" value="" class="layui-input" disabled>
            <input type="hidden" name="appname" readonly="true" value="" class="layui-input" disabled>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">防刷状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="reqlimit_enable" value="record"  lay-filter="reqlimitEnable" title="只记录不限制" checked="">
                        <input type="radio" name="reqlimit_enable" value="on" lay-filter="reqlimitEnable" title="开启">
                        <input type="radio" name="reqlimit_enable" value="off" lay-filter="reqlimitEnable" title="关闭">                                                                            
                    </div>  
            </div>  
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">修改时间</label>
                <div class="layui-input-block">
                  <input type="input" name="updatetime" readonly="true" value="" class="layui-input" disabled>
                </div> 
            </div> 
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>限流配置项</legend>
            </fieldset>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">IP限流</label>
                <div class="layui-input-inline"> 
                    <input type="checkbox" checked="" name="iplimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                
                </div>
                <div class="layui-input-inline" style="width:130px">  
                    <input type="text" name="ip_rate" id="ip_rate" placeholder="100/60[请求/秒]" value="" class="layui-input">
                </div> 
                <div class="layui-input-inline" style="width:130px">  
                    <button type="button" style="width:160px" class="layui-btn layui-btn-normal" onclick="clickme('ip_rate','ip_rate')">修改IP限流阀值</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">C段IP限流</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="ciplimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                  
                </div>
                <div class="layui-input-inline" style="width:130px">  
                    <input type="text" name="cip_rate" id="cip_rate" placeholder="100/60[请求/秒]" value="" class="layui-input">
                </div> 
                <div class="layui-input-inline" style="width:130px">  
                    <button type="button" style="width:160px" class="layui-btn layui-btn-normal" onclick="clickme('cip_rate','cip_rate')">修改C段IP阀值</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">ip+uri限流</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="ipurilimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                  
                </div>
                <div class="layui-input-inline" style="width:130px">  
                    <input type="text" name="ipuri_rate" id="ipuri_rate" placeholder="100/60[请求/秒]" value="" class="layui-input">
                </div> 
                <div class="layui-input-inline" style="width:130px">  
                    <button type="button" style="width:160px" class="layui-btn layui-btn-normal" onclick="clickme('ipuri_rate','ipuri_rate')">修改IpUri限流阀值</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">UA限流</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="ualimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                   
                </div>
                <div class="layui-input-inline" style="width:130px">  
                    <input type="text" name="ua_rate" id="ua_rate" placeholder="100/60[请求/秒]" value="" class="layui-input">
                </div> 
                <div class="layui-input-inline" style="width:130px">  
                    <button type="button" style="width:160px" class="layui-btn layui-btn-normal" onclick="clickme('ua_rate','ua_rate')">修改UA限流阀值</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">Referer限流</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="rflimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline" style="width:130px">  
                    <input type="text" name="rf_rate" id="rf_rate" placeholder="100/60[请求/秒]" value="" class="layui-input">
                </div> 
                <div class="layui-input-inline" style="width:130px">  
                    <button type="button" style="width:160px" class="layui-btn layui-btn-normal" onclick="clickme('rf_rate','rf_rate')">修改Rferer限流阀值</button>
                </div> 
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">总qps限流</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="alllimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline" style="width:130px">  
                    <input type="text" name="all_rate" id="all_rate" placeholder="100/60[请求/秒]" value="" class="layui-input">
                </div> 
                <div class="layui-input-inline">  
                    <button type="button" style="width:160px" class="layui-btn layui-btn-normal" onclick="clickme('all_rate','all_rate')">修改总限流阀值</button>
                </div> 
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>特定标识限流</legend>
            </fieldset>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="extralimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="ruleBtn" style="width:200px" type="button">特定标识限流策略</button>
                </div> 
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>自定义URL限流</legend>
            </fieldset>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <input type="checkbox" checked="" name="custom_urllimit_enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">                                                 
                </div>
                <div class="layui-input-inline">  
                    <button class="layui-btn layui-btn-primary layui-border-green" id="urlRuleBtn" style="width:200px" type="button">自定义URL限流策略</button>
                </div> 
            </div>
            <!--  
            <div class="layui-form-item" style="margin-top: 20px;">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
                </div>
            </div>
            -->
        </form>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>

  function randomString(e) {  
    e = e || 16;
    var t = "abcdefghijkmnpqrstuvwxyz23456789",
    a = t.length,
    n = "lb_";
    for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
    return n
  }

    function clickme(obj,elmId){
      //console.log(obj);
      var val = document.getElementById(elmId).value;
      //console.log(val)
      var bodystr = {"name":obj,"value":val};
      console.log(JSON.stringify(bodystr))
    		$.ajax({
    		   url: "/xwaf/config/v1/EditReqlimitConfig" + location.search,
    		   type: "GET",
    		   headers:{'X-Requested-With':'XMLHttpRequest'},
           type: "post",
           data: JSON.stringify(bodystr),
           dataType: "json",
    		   success: function (resp) {
    				  if (resp.code == 0 ) {
                layer.msg('更改成功', {icon: 1});
              }else{
                layer.msg(resp.msg,{icon:2});
              }
    			  }
    	    });
    }

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table;
            $ = layui.$;

			$.ajax({
			   url: "/xwaf/config/v1/GetReqlimitConfig" + location.search,
			   type: "GET",
			   headers:{'X-Requested-With':'XMLHttpRequest'},
			   success: function (resp) {
          
					if (resp.id > 0 ) {
      				  form.val('UpdateInfo', {
                  "id": resp.id
                  ,"appname": resp.appname
                  ,"reqlimit_enable": resp.reqlimit_enable
                  ,"ipurilimit_enable": resp.ipurilimit_enable
                  ,"ipuri_rate": resp.ipuri_rate
                  ,"iplimit_enable": resp.iplimit_enable
                  ,"ip_rate": resp.ip_rate
                  ,"ciplimit_enable": resp.ciplimit_enable
                  ,"cip_rate": resp.cip_rate
                  ,"ualimit_enable": resp.ualimit_enable
                  ,"ua_rate": resp.ua_rate
                  ,"rflimit_enable": resp.rflimit_enable
                  ,"rf_rate": resp.rf_rate
                  ,"alllimit_enable": resp.alllimit_enable
                  ,"all_rate": resp.all_rate       
                  ,"extralimit_enable": resp.extralimit_enable        
                  ,"custom_urllimit_enable": resp.custom_urllimit_enable        
                  ,"updatetime": resp.updatetime                              
      				  }) 
            }else{
              layer.msg(resp.msg,{icon:2});
            }
				  }
		    });	

  form.on('radio(reqlimitEnable)', function(data){
    var bodystr = {"name":this.name,"value":data.value};
			$.ajax({
			   url: "/xwaf/config/v1/EditReqlimitConfig" + location.search,
			   type: "GET",
			   headers:{'X-Requested-With':'XMLHttpRequest'},
         type: "post",
         data: JSON.stringify(bodystr),
         dataType: "json",
			   success: function (resp) {
					  if (resp.code == 0 ) {
              layer.msg('更改成功', {icon: 1});
            }else{
              layer.msg(resp.msg,{icon:2});
            }
				  }
		    });
  });

  form.on('switch(switchTest)', function(data){
    var bodystr = {"name":this.name,"value":this.checked};
    //console.log(JSON.stringify(bodystr))
			$.ajax({
			   url: "/xwaf/config/v1/EditReqlimitConfig" + location.search,
			   type: "GET",
			   headers:{'X-Requested-With':'XMLHttpRequest'},
         type: "post",
         data: JSON.stringify(bodystr),
         dataType: "json",
			   success: function (resp) {
					  if (resp.code == 0 ) {
              layer.msg('更改成功', {icon: 1});
            }else{
              layer.msg(resp.msg,{icon:2});
            }
				  }
		    });
        //layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
  });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

                data.field.appname = data.field.appname.replace(/^\s*|\s*$/g,""); //替换空格
                data.field.clsobject = data.field.clsobject.replace(/server|;/g,"");
                data.field.clsobject = data.field.clsobject.replace(/：/g,":");
                data.field.clsobject = data.field.clsobject.replace(/，|\r|\n/g,",");
                data.field.clsobject = data.field.clsobject.replace(/^\s*|\s*$/g,"");
                data.field.clsobject = data.field.clsobject.replace(/\s/g,"");
					      console.log(data.field);

			          layer.confirm('确定修改?', {icon: 3, title:'提示',yes: function(index){
                     var index2 = layer.load(0, {shade: false});
                     layer.msg('稍等片刻');
                     $.ajax({
                       url: "/cachetools/v1/Update" + location.search,
                       type: "post",
                       data: JSON.stringify(data.field),
                       dataType: "json",
                       success: function (resp) {
                                layer.close(index2);
                                 if(resp.code == 0){
                                    layer.msg('修改成功', {icon: 1});
									                  //window.location.reload();
                                 }else{
                                    layer.msg(resp.msg,{icon:2});
                                 }
                        }
                      });		  	  
                  },
                  cancel: function(index, layero){ 
                    layer.close(index);
                    layer.close(index2);
		                console.log("不操作");
                  } 
                });
              return false;
        });


        $('#ruleBtn').on("click",function(){
                layer.open({
                    title: '特定标识限流策略',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/reqlimit_extrule_policy.html'+ location.search,
                });
        });

        $('#urlRuleBtn').on("click",function(){
            window.open('/page/xwaf/reqlimit_customurl_policy.html'+ location.search, "_blank"); 
               /**
                layer.open({
                    title: '自定义URL限流策略',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: '/page/xwaf/reqlimit_customurl_policy.html'+ location.search,
                });
                **/
        });

$(".static-marks").mouseover(function() {
    layer.tips('静态文件忽略不进行拦截分析', this, {
      tips: [1, "#000"],
      time:3000
    });
});

$(".intranet-marks").mouseover(function() {
    layer.tips('从内网IP过来的请求不做任何操作', this, {
      tips: [1, "#000"],
      time:3000
    });
});
    });
</script>
</body>
</html>